package com.small.nacos.client.naming.core;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.small.nacos.client.naming.net.NamingProxy;

import java.util.List;

/**
 * @Author zhoujin
 * @Date 2022/10/13 13:52
 */
public class HostReactor {

    private NamingProxy serverProxy;

    public HostReactor(NamingProxy serverProxy) {
        this.serverProxy = serverProxy;
    }


    public ServiceInfo getServiceInfoDirectlyFromServer(String serviceName, List<String> clusters) throws NacosException {
        String result = serverProxy.queryList(serviceName,StringUtils.join(clusters, ","));
        if (StringUtils.isNotEmpty(result)) {
            return JacksonUtils.toObj(result, ServiceInfo.class);
        }
        return null;
    }
}
